package com.example.administrator.denglu_zhuce;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.sql.Time;

/**
 * Created by Administrator on 2016/11/28.
 */
public class ZhuCe extends AppCompatActivity {

    private Button button_huoquyanzhengma;
    private TimeCount time;
   private EditText edit_shoujihaoma;
    Handler handler;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.zhu_ce);

        RequestQueue mQueue = Volley.newRequestQueue(this);

        StringRequest s = new StringRequest("http://api.zhaibao.cn/sendRegCode?mobile&version=1.0&deviceType=2", new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
            Log.d("TAG", response);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("TAG", error.getMessage(), error);
            }
        });

        mQueue.add(s);


        time = new TimeCount(60000, 1000);

        edit_shoujihaoma = (EditText) findViewById(R.id.edit_shoujihaoma);


        button_huoquyanzhengma =(Button) findViewById(R.id.button_huoquyanzhengma);
        button_huoquyanzhengma.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                time.start();
            }
        });

        String numberP = edit_shoujihaoma.getText().toString();
        if (numberP.equals(null)  || numberP.equals("")) {
            Toast.makeText(ZhuCe.this,"手机号码不能为空",Toast.LENGTH_LONG).show();

        }else {

        }
    }

    class TimeCount extends CountDownTimer {
        public TimeCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }


        @Override
        public void onFinish() {// 计时完毕
            button_huoquyanzhengma.setText("获取验证码");
            button_huoquyanzhengma.setClickable(true);
        }

        @Override
        public void onTick(long millisUntilFinished) {// 计时过程
            button_huoquyanzhengma.setClickable(false);//防止重复点击
            button_huoquyanzhengma.setText(millisUntilFinished / 1000 + "秒重新发送");
        }
    }



}
